package com.zhangzhan.gulimallorder.vos;

import com.zhangzhan.gulimallcommcon.util.MyCollUtil;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author 张一恒
 * @version 1.0
 * @description: 订单页实体类
 * @date 2024/6/30 11:21
 */

public class ConfirmVo {

    //用户收货地址信息
    @Getter
    @Setter
    private List<MemberAddrVo> memberAddrVos;

    //购物车信息
    @Getter
    @Setter
    private List<MemberCartVo> memberCartVos;

    //积分
    @Getter
    @Setter
    private Integer integration;

    //库存判断
    @Getter
    @Setter
    private Map<Long,Boolean> hasInventory;

    //保证幂等性
    @Getter
    @Setter
    private String uid;

    public Integer getCount() {
        int count = 0;
        if (MyCollUtil.isNotEmpty(memberCartVos)) {
            for (MemberCartVo item : memberCartVos) {
                count = count + item.getCount();
            }
        }
        return count;
    }

    //商品总金额
    public BigDecimal getTotalPrice() {
        BigDecimal totalPrice = new BigDecimal(0);
        if (MyCollUtil.isNotEmpty(memberCartVos)) {
            for (MemberCartVo item : memberCartVos) {
                totalPrice = totalPrice.add(item.getPrice().multiply(new BigDecimal(item.getCount())));
            }
        }
        return totalPrice;
    }

    //应付总金额
//    private BigDecimal theTotalAmountDue;

    public BigDecimal getTheTotalAmountDue() {
        return getTotalPrice();
    }
}
